package gld;

import static robocode.util.Utils.normalRelativeAngle;

public class Calculation {

	public double headOnTargetTurn(double targetBearingRadians, double headingRadians, double radarHeadingRadians) {
		double absoluteBearing = targetAbsoluteBearing(targetBearingRadians, headingRadians);
		double absoluteAngle = absoluteBearing - radarHeadingRadians;
		return normalRelativeAngle(absoluteAngle);
	}
	
	public double targetAbsoluteBearing(double targetBearingRadians, double headingRadians) {
		return targetBearingRadians + headingRadians;
	}
	
	public double targetLateralVelocity(double targetVelocity, double targetHeadingRadians, double targetAbsoluteBearing) {
		return targetVelocity * Math.sin(targetHeadingRadians - targetAbsoluteBearing);
	}
	
	public double bulletSpeed(double bulletPower) {
		return 20 - bulletPower * 3;
	}
 
	public double maxEscapeAngle(double bulletPower) {
		return Math.asin(8 / bulletSpeed(bulletPower));
	}
	
	public double targetLocationX(double targetAbsoluteBearing, double targetDistance, double x) {
		return x + Math.sin(targetAbsoluteBearing) * targetDistance;
	}
	
	public double targetLocationY(double targetAbsoluteBearing, double targetDistance, double y) {
		return y + Math.sin(targetAbsoluteBearing) * targetDistance;
	}
	
}
